package com.chaos.meta;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author naicha
 */
@SpringBootApplication(exclude= {SecurityAutoConfiguration.class})
@MapperScan("com.chaos.meta.mapper")
@EnableSwagger2
public class MetaApplication {

    final static int defaultTimeout = 60000;

    public static void main(String[] args) {
		SpringApplication.run(MetaApplication.class, args);
	}

    /**
     * RestTemplate Bean, 解决RestTemplate由于依赖ClientHttpRequestFactory对象无法直接注入的问题。
     */
    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(defaultTimeout);
        requestFactory.setReadTimeout(defaultTimeout);
        restTemplate.setRequestFactory(requestFactory);
        return restTemplate;
    }
}
